package com.ruoyi.project.channel.incomeInfo.controller;

import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.incomeInfo.domain.IncomeInfo;
import com.ruoyi.project.channel.incomeInfo.service.IIncomeInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 佣金信息操作处理
 * 
 * @author CAIN
 * @date 2021-02-04
 */
@Controller
@RequestMapping("/channel/incomeInfo")
public class IncomeInfoController extends BaseController
{
    private String prefix = "channel/incomeInfo";
	
	@Autowired
	private IIncomeInfoService incomeInfoService;
	
	@RequiresPermissions("channel:incomeInfo:view")
	@GetMapping()
	public String incomeInfo()
	{
	    return prefix + "/incomeInfo";
	}
	
	/**
	 * 查询佣金列表
	 */
	@RequiresPermissions("channel:incomeInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IncomeInfo incomeInfo)
	{
		startPage();
        List<IncomeInfo> list = incomeInfoService.selectIncomeInfoList(incomeInfo);
		return getDataTable(list);
	}
	/**
	 * 查询佣金列表
	 */
	@PostMapping("/list/self")
	@ResponseBody
	public TableDataInfo listSelf(IncomeInfo incomeInfo)
	{
		incomeInfo.setUserId(ShiroUtils.getUserId());
		startPage();
		List<IncomeInfo> list = incomeInfoService.selectIncomeInfoList(incomeInfo);
		return getDataTable(list);
	}
	
	/**
	 * 导出佣金列表
	 */
	@RequiresPermissions("channel:incomeInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IncomeInfo incomeInfo)
    {
    	List<IncomeInfo> list = incomeInfoService.selectIncomeInfoList(incomeInfo);
        ExcelUtil<IncomeInfo> util = new ExcelUtil<IncomeInfo>(IncomeInfo.class);
        return util.exportExcel(list, "incomeInfo");
    }
	
	/**
	 * 新增佣金
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存佣金
	 */
	@RequiresPermissions("channel:incomeInfo:add")
	@Log(title = "佣金", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IncomeInfo incomeInfo)
	{		
		return toAjax(incomeInfoService.insertIncomeInfo(incomeInfo));
	}

	/**
	 * 修改佣金
	 */
	@GetMapping("/edit/{incomeId}")
	public String edit(@PathVariable("incomeId") Long incomeId, ModelMap mmap)
	{
		IncomeInfo incomeInfo = incomeInfoService.selectIncomeInfoById(incomeId);
		mmap.put("incomeInfo", incomeInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存佣金
	 */
	@RequiresPermissions("channel:incomeInfo:edit")
	@Log(title = "佣金", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IncomeInfo incomeInfo)
	{		
		return toAjax(incomeInfoService.updateIncomeInfo(incomeInfo));
	}
	
	/**
	 * 删除佣金
	 */
	@RequiresPermissions("channel:incomeInfo:remove")
	@Log(title = "佣金", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(incomeInfoService.deleteIncomeInfoByIds(ids));
	}
	
}
